package models

import "gorm.io/gorm"

type LoginDao struct {
	Id       int    `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
	Username string `gorm:"column:username;type:varchar(100);NOT NULL" json:"username"`
	Email    string `gorm:"column:email;type:varchar(100);NOT NULL" json:"email"`
	Password string `gorm:"column:password;type:varchar(200);NOT NULL" json:"password"`
}

func (s *LoginDao) TableName() string {
	return "login"
}

func (s *LoginDao) First(tx *gorm.DB) error {
	tx = tx.Model(&s)
	if s.Username != "" {
		tx = tx.Where("username = ?", s.Username)
	}
	if s.Password != "" {
		tx = tx.Where("password = ?", s.Password)
	}
	if err := tx.First(&s).Error; err != nil {
		return err
	}
	return nil
}
